﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
public static class ItemParamEditorTool
{
    public class ItemGameObjectGroupPair
    {
        public string Group;
        public GameObject Object;
        
    }
    public static string GetVarName(System.Linq.Expressions.Expression<Func<string, string>> exp)
    {
        return ((System.Linq.Expressions.MemberExpression)exp.Body).Member.Name;
    }
        /*public static string[] GetAllPrefabs(string directory)
        {
            if (string.IsNullOrEmpty(directory) || !directory.StartsWith("Assets"))
                throw new ArgumentException("folderPath");

            string[] subFolders = Directory.GetDirectories(directory);
            string[] guids = null;
            string[] assetPaths = new string[1];
            int i = 0, iMax = 0;
            foreach (var folder in subFolders)
            {
                guids = AssetDatabase.FindAssets("t:Prefab", new string[] { folder });
                assetPaths = new string[guids.Length];
                for (i = 0, iMax = assetPaths.Length; i < iMax; ++i)
                {
                    assetPaths[i] = AssetDatabase.GUIDToAssetPath(guids[i]);
                    Debug.Log(assetPaths[i]);
                }
            }
            return assetPaths;
        }*/
        [MenuItem("Tools/Test")]
    public static List<ItemGameObjectGroupPair> GetPrefab()
    {
        var list = new List<ItemGameObjectGroupPair>();
        var folders=AssetDatabase.GetSubFolders("Assets/Resources/Prefabs/Item");

    //    Debug.Log(folders.Length);
        foreach(var x in folders)
        {
            var sub = 
            AssetDatabase.FindAssets("t:Prefab",new string[] { x });
            List<GameObject> prefabs = new List<GameObject>();
       //     Debug.Log(x+" "+sub.Length);
            var name = x.Split('/')[x.Split('/').Length - 1];
            foreach(var y in sub)
            {
                prefabs.Add(AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GUIDToAssetPath(y)));
             //   Debug.Log(prefabs.Last<GameObject>());
                list.Add(new ItemGameObjectGroupPair { Group = name, Object = prefabs.Last<GameObject>() });
            }
        }
        return list;
    }
}
